<template>
  <div class="param-main">
    <el-form ref="tblMain" :model="tblMain" labelPosition="right" inline="" label-suffix=":" label-width="100px">
      <el-row :span="24">
        <el-col :span="6">
          <el-form-item label="订单编号">
            <el-input v-model="tblMain.param.orderId" size="small" placeholder=""></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="退货状态">
            <el-select v-model="tblMain.param.storeStatus" size="small" placeholder="" style="width: 100%;">
              <el-option label="未审核" value="0" />
              <el-option label="已同意" value="1" />
              <el-option label="已驳回" value="2" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="page-pane2">
        <el-button type="primary" size="small" @click="initTableData()">查询</el-button>
        <el-button size="small" @click="dataReset()">清空</el-button>
      </div>
    </el-form>
    <div style="height: calc(100% - 160px);">
      <el-table ref="tblMain" style="margin-top: 10px;" :data="tblMain.items" @selection-change="handleSelectionChange"
        v-loading.body="tblMain.loading" height="100%" border stripe>
        <el-table-column type="index" width="80" label="序号" align="center"></el-table-column>
        <el-table-column label="操作" align="center" width="200px">
          <template slot-scope="scope">
            <el-button type="text" @click="detailRow(scope.row)">明细</el-button>
            <el-divider v-if="scope.row.storeStatus == '0'" direction="vertical"></el-divider>
            <el-button v-if="scope.row.storeStatus == '0'" type="text" @click="finishRow(scope.row)">同意</el-button>
            <el-divider v-if="scope.row.storeStatus == '0'" direction="vertical"></el-divider>
            <el-button v-if="scope.row.storeStatus == '0'" type="text" @click="rejectRow(scope.row)">驳回</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="storeStatus" width="150" label="退货状态" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.storeStatus == '0'" type="primary">未审核</el-tag>
            <el-tag v-else-if="scope.row.storeStatus == '1'" type="success">已同意</el-tag>
            <el-tag v-else-if="scope.row.storeStatus == '2'" type="warning">已驳回</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="orderSn" label="订单编号" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productName" label="商品名称" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column prop="totalAmount" label="订单金额" align="center" show-overflow-tooltip></el-table-column>
      </el-table>
      <el-pagination style="margin-top: 10px" :current-page.sync="tblMain.currentPage" :page-size="tblMain.pageSize"
        :total="tblMain.total" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange"
        @current-change="handleCurrentChange"></el-pagination>
    </div>
    <refund-examine-dialog ref="modalForm"></refund-examine-dialog>
  </div>
</template>
<script>
import RefundExamineDialog from './components/RefundExamineDialog'
import tool from '@/tool'
import {
  storeMasterThemeAuditList,
  storeMasterThemeAuditConfirm,
  storeMasterThemeAuditReject
} from '@/api/business'
export default ({
  name: 'RefundExamineList',
  components: {
    RefundExamineDialog
  },
  data () {
    return {
      tblMain: tool.genTableData({
        param: {
          orderId: '',
          storeStatus: ""
        },
        items: []
      }),
    }
  },
  mounted () {
    this.initTableData();
  },
  methods: {
    async finishRow (val) {
      this.$confirm('确定同意该退货订单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        let params = {
          id: val.id
        }
        await this.finishTblMain(params)
      }).catch(() => {
      })
    },
    finishTblMain (params) {
      let me = this
      me.tblMain.loading = true
      storeMasterThemeAuditConfirm(params).then(res => {
        me.tblMain.loading = false
        let data = res.data
        if (data && data.code == 0) {
          me.$message.success('设置成功')
          this.initTableData()
        }
      }).catch(() => {
        me.$message.error('请求失败')
        me.tblMain.loading = false
      })
    },
    async rejectRow (val) {
      this.$confirm('确定驳回该退货订单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        let params = {
          id: val.id
        }
        await this.rejectTblMain(params)
      }).catch(() => {
      })
    },
    rejectTblMain (params) {
      let me = this
      me.tblMain.loading = true
      storeMasterThemeAuditReject(params).then(res => {
        me.tblMain.loading = false
        let data = res.data
        if (data && data.code == 0) {
          me.$message.success('设置成功')
          this.initTableData()
        }
      }).catch(() => {
        me.$message.error('请求失败')
        me.tblMain.loading = false
      })
    },
    detailRow (val) {
      this.$refs.modalForm.edit(val);
    },
    dataReset () {
      this.tblMain.currentPage = 1
      this.tblMain.pageSize = 10
      this.tblMain.param.orderId = ''
      this.tblMain.param.storeStatus = ''
      this.initTableData()
    },
    handleSelectionChange (val) {
      this.tblMain.selection = val;
    },
    handleSizeChange (val) {
      this.tblMain.pageSize = val
      this.initTableData()
    },
    handleCurrentChange (val) {
      this.tblMain.currentPage = val
      this.initTableData()
    },
    initTableData () {
      let me = this
      me.tblMain.selection = []
      let param = {
        orderSn: me.tblMain.param.orderId,
        storeStatus: me.tblMain.param.storeStatus,
        page: me.tblMain.currentPage,
        size: me.tblMain.pageSize
      }
      me.tblMain.loading = true
      storeMasterThemeAuditList(param).then(res => {
        me.tblMain.loading = false
        let data = res.data
        if (data && data.code == 0) {
          me.tblMain.items = data.data.records
          me.tblMain.total = data.data.total
        }
      })
    },
  }
})
</script>
